package com.oreilly.ez.base;


import com.google.common.eventbus.EventBus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;

@Component
public class SysEventContext {

    @Autowired
    private EventBus eventBus;


    @Autowired
    private List<SysEventListener> eventListenerList;



    @DependsOn("eventBus")
    @PostConstruct
    public void init(){


        for (SysEventListener listener : eventListenerList) {
            System.out.println("##subscriber = " + listener);
            eventBus.register(listener);
        }
    }



    public void post(Object event) {
        eventBus.post(event);
    }




}
